package com.hzhr.iot.device.dao;

import com.hzhr.iot.device.dao.mapper.custom.CollectDataEntityCustomMapper;
import com.hzhr.iot.device.dao.mapper.generator.CollectDataEntityMapper;
import com.hzhr.iot.device.entity.CollectDataEntity;
import com.hzhr.iot.device.entity.ext.CollectDataEntityExt;
import com.hzhr.iot.device.queryModel.custom.CollectDataCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class CollectDataDao {
    @Autowired
    CollectDataEntityMapper collectDataEntityMapper;
    @Autowired
    CollectDataEntityCustomMapper collectDataEntityCustomMapper;

    public int insert(CollectDataEntity record) {
        if (record == null) return 0;
        int changeCount = collectDataEntityMapper.insert(record);
        return changeCount;
    }

    public int delete(CollectDataCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = collectDataEntityCustomMapper.delete(queryModel);
        return changeCount;
    }

    public int update(CollectDataEntity record) {
        if (record == null) return 0;
        int changeCount = collectDataEntityMapper.updateByPrimaryKey(record);
        return changeCount;
    }

    public int updateProps(CollectDataCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = collectDataEntityCustomMapper.updateProps(queryModel);
        return changeCount;
    }

    public CollectDataEntity selectEntity(CollectDataCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<CollectDataEntityExt> extList = collectDataEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<CollectDataEntity> selectEntityList(CollectDataCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<CollectDataEntityExt> extList = collectDataEntityCustomMapper.selectExt(queryModel);
        if (extList == null) return null;
        List<CollectDataEntity> entityList = new ArrayList<>();
        for (CollectDataEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public CollectDataEntityExt selectExt(CollectDataCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<CollectDataEntityExt> extList = collectDataEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<CollectDataEntityExt> selectExtList(CollectDataCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<CollectDataEntityExt> extList = collectDataEntityCustomMapper.selectExt(queryModel);
        return extList;
    }

    public int selectCount(CollectDataCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = collectDataEntityCustomMapper.selectCount(queryModel);
        return count;
    }
}
